package cn.tedu.rabbitmqspringboot.m4;

import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Component

public class Consumer {

    //每个 @RabbitListener 都会注册成为一个消费者
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue, //随机队列名,false 非持久,true独占,true自动删除
            //交换机,declare=false 表示在这里不重复定义交换机,在main中定义
            exchange = @Exchange(name = "direct_logs",declare = "false"),
            key={"error"}
    ))
    public void receive1(String msg){

        System.out.println("消费者1收到:"+msg);
    }

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue, //随机队列名,false 非持久,true独占,true自动删除
            //交换机,declare=false 表示在这里不重复定义交换机,在main中定义
            exchange = @Exchange(name = "direct_logs",declare = "false"),
            key={"info","warning","error"}
    ))
    public void receive2(String msg){

        System.out.println("消费者2收到:"+msg);
    }

}
